<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>{$id}</title>
	<include file="Public:header" />
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerForm.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDateEditor.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerComboBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerCheckBox.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerButton.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerDialog.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerRadio.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerSpinner.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerTextBox.js" type="text/javascript"></script> 
    <script src="__PUBLIC__/lib/ligerUI/js/plugins/ligerTip.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/jquery-validation/jquery.validate.min.js" type="text/javascript"></script> 
    <script src="__PUBLIC__/lib/jquery-validation/jquery.metadata.js" type="text/javascript"></script>
    <script src="__PUBLIC__/lib/jquery-validation/messages_cn.js" type="text/javascript"></script>
    <script type="text/javascript"> 
        var groupicon = "__PUBLIC__/lib/ligerUI/skins/icons/communication.gif";
        $(function ()
        {
            $.metadata.setType("attr", "validate");
            //创建表单结构
            var mainform = $("#detailform");
            mainform.ligerForm({
                inputWidth: 170, labelWidth: 90, space: 20,
                fields: [
                { name: "id", type: "hidden" },
                { name: "pid", type: "hidden", },
                { name: "level", type: "hidden", },
                { display: "<eq name='level' value='1'>应用</eq><eq name='level' value='2'>模块</eq><eq name='level' value='3'>操作</eq> 名称", name: "name", newline: true, type: "text", validate: { required: true,minlength:3 }, group: "基础信息", groupicon: groupicon}, 
                { display: "显示名称", name: "title", newline: true, type: "text", validate: { required: true,minlength:3 }},
                { display: "分组", name: "group_id", newline: true, type: "select", comboboxName: "Name1", options: {valueFieldID: "group_id",data:<php>echo json_encode($list);</php>}},
                { display: "状态", name: "status", newline: true, type: "select", comboboxName: "Name2", options: {valueFieldID: "status",data:[{text:"启用",id:"1"},{text:"禁用",id:"0"}]}},
                { display: "图标<span id='span_icon'></span>", name: "nodeicon", newline: true, type: "select"},
                { display: "备注", name: "remark", newline: true, type: "textarea",width:200,space:30}

                ],
                buttons: [{ text: '确定',type:"submit", icon: 'ok',onclick: function (item) {save();} },
                          { text: '取消',type:"", onclick: function (item) {cancel();  } }]
            });
              $("#pid").val({$pid});
              $("#level").val({$level});
              $("#nodeicon").ligerComboBox({
                  onBeforeOpen: f_selectIcon, valueFieldID: 'nodeicon'
               });
         
         
            var validator = $("#detailform").validate({
                //调试状态，不会提交数据的
                debug: false,
                errorPlacement: function (lable, element)
                {

                    if (element.hasClass("l-textarea"))
                    {
                        element.addClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field"))
                    {
                        element.parent().addClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                    $(element).attr("title", lable.html()).ligerTip();
                },
                success: function (lable)
                {
                    var element = $("#" + lable.attr("for"));
                    if (element.hasClass("l-textarea"))
                    {
                        element.removeClass("l-textarea-invalid");
                    }
                    else if (element.hasClass("l-text-field"))
                    {
                        element.parent().removeClass("l-text-invalid");
                    }
                    $(element).removeAttr("title").ligerHideTip();
                },
                submitHandler: function ()
                {
                    alert("Submitted!");
                }
            }); 
        }); 
        
        function save()
        {
     	   $.post('__URL__/add/',$("#detailform").serialize(),function(data){
                var win = parent || window;
                win.LG.showMessage(data, function () { 
                    win.LG.closeAndReloadParent(null, "Node_index");
                });
            });
        }
        function cancel()
        {
            var win = parent || window;
            win.LG.closeCurrentTab(null);
        }
        
        function f_selectIcon()
        {
            $.ligerDialog.open({ title: '选择图标', name:'winselector',width: 600, height: 500, url: '__URL__/selectIcon/', buttons: [
                { text: '确定', onclick: f_selectIconOK },
                { text: '取消', onclick: f_selectIconCancel }
            ]
            });
            return false;
        }

        function f_selectIconOK(item, dialog)
        {
			var fn = dialog.frame.f_select || dialog.frame.window.f_select; 
            var data = fn(); 
            if (!data)
            {
                alert('请选择图标!');
                return;
            }
            $("#nodeicon").val(data);
            jiconlist = $("#image");
            if (!jiconlist.length) //jiconlist = $('<ul class="iconlist"></ul>').appendTo('body');
            $("#span_icon").html('<img id="image" src="" width="20" height="20"/>');
            $("#image").attr("src","__ROOT__"+data);
            dialog.close();
        }

        function f_selectIconCancel(item, dialog)
        {
            dialog.close();
        }
    </script> 

</head>
<body style="padding:10px"> 
新增节点类型：<eq name="level" value="1">应用</eq><eq name="level" value="2">模块</eq><eq name="level" value="3">操作</eq>===>上级：{$ptitle} </div>
    <form id="detailform">
    </form> 
 </body>
</html>

